% Jiaxi He
% Swinburne University of Technology
% jiaxihe@swin.edu.au

function d = SA(u)
[m,n]=size(u);
d=zeros(m,n);

% d(1,1)=u(2,1)+u(1,2);
% d(1,n)=u(2,n)+u(1,n-1);
% d(m,1)=u(m,2)+u(m-1,1);
% d(m,n)=u(m-1,n)+u(m,n-1);
% 
% d(1,2:n-1)=u(1,1:n-2)+u(1,3:n)+u(2,2:n-1);
% d(m,2:n-1)=u(m,1:n-2)+u(m,3:n)+u(m-1,2:n-1);
% d(2:m-1,1)=u(1:m-2,1)+u(3:m,1)+u(2:m-1,2);
% d(2:m-1,n)=u(1:m-2,n)+u(3:m,n)+u(2:m-1,n-1);
% 
% d(2:m-1,2:n-1)=u(1:m-2,2:n-1)+u(3:m,2:n-1)+u(2:m-1,1:n-2)+u(2:m-1,3:n);


d(1,1)=u(2,1)+u(1,2)+u(m,1)+u(1,n);
d(1,n)=u(2,n)+u(1,n-1)+u(1,1)+u(m,n);
d(m,1)=u(m,2)+u(m-1,1)+u(1,1)+u(m,n);
d(m,n)=u(m-1,n)+u(m,n-1)+u(1,n)+u(m,1);

d(1,2:n-1)=u(1,1:n-2)+u(1,3:n)+u(2,2:n-1)+u(m,2:n-1);
d(m,2:n-1)=u(m,1:n-2)+u(m,3:n)+u(m-1,2:n-1)+u(1,2:n-1);
d(2:m-1,1)=u(1:m-2,1)+u(3:m,1)+u(2:m-1,2)+u(2:m-1,n);
d(2:m-1,n)=u(1:m-2,n)+u(3:m,n)+u(2:m-1,n-1)+u(2:m-1,1);

d(2:m-1,2:n-1)=u(1:m-2,2:n-1)+u(3:m,2:n-1)+u(2:m-1,1:n-2)+u(2:m-1,3:n);